﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using NCT.Entity;
using System.Collections.Generic;
using WindowsPhonePostClient;
using System.ComponentModel;

namespace NCT.DataAccessComponents
{
    /// <summary>
    /// do for spec item
    /// </summary>
    public class ItemDAC
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propChanged)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propChanged));
        }
        Item item;
        string lyricSong = "";

        public string LyricSong
        {
            get { return lyricSong; }
            set 
            { 
                if ( lyricSong != value )
                {
                    lyricSong = value;
                    OnPropertyChanged("LyricSong");
                }
            }
        }
        public Item Item
        {
            get { return item; }
            set 
            {
                if ( item != value )
                {
                    item = value;
                    getSongLyric(Item.Key, "getSongLyric");
                }
            }
        }

        private void getSongLyric(string songId, string action)
        {
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("secretkey", "nct@mobile!team");
            parameters.Add("action", action);
            parameters.Add("songkey", songId);
            parameters.Add("type", "1");
            parameters.Add("deviceinfo", NCTConstants.DEVICE_INFOR);

            PostClient proxy = new PostClient(parameters);
            proxy.DownloadStringCompleted += (sender, e) =>
            {
                if (e.Error == null)
                {
                    LyricSong = e.Result;
                }
            };
            proxy.DownloadStringAsync(new Uri(NCTConstants.REST_SERVICE_V3_URL, UriKind.Absolute));
        }

    }
}
